<template>
	<view class="content">
		<image class="upload" src="../../static/images/text-image-modified.png" @click="uploadImg"></image>
	</view>
</template>
<script>
	export default {
		name: "upload",
		data() {
			return {
				list: []
			}
		},
		onLoad() {

		},
		methods: {
			uploadImg() {
				uni.chooseImage({
					count: 1,
					success: (res) => {
						console.log(res.tempFiles)
						this.urlTobase64(res.tempFilePaths[0])
					}
				})

			},

			urlTobase64(url) {
				uni.request({
					url: url,
					method: 'GET',
					responseType: 'arraybuffer',
					success: ress => {
						let base64 = wx.arrayBufferToBase64(ress.data); //把arraybuffer转成base64 
						// base64 =  base64 
						// console.log(base64)
					uni.request({
						url: 'https://aip.baidubce.com/rpc/2.0/ai_custom/v1/classification/garbge_class?access_token=24.9c451242eec61d8d663a5f545cbf7987.2592000.1701152819.282335-39542891',
						method:'POST',
						data: {
							image: base64
						},
						header: {
							'Content-Type':'application/json'
						},
						success: (res) => {
							console.log(res.data)
							this.list=res.data.results
							let name=this.list[0].name
							let category;
							if(name=="kitchenGarbge_baibaozhou_"){
								category="厨余垃圾"
							}
							else if(name=="recycGarbge_book_"){
								category="可回收垃圾"
							}
							else if(name=="otherGarbge_PE_"){
								category="其他垃圾"
							}
							else if(name=="harmfulGarbge_LED_"){
								category="有害垃圾"
							}
							uni.showModal({
								title:'您所选的垃圾类别为:'+category,
								showCancel:false,
								// content:this.list.lajitip,
								confirmText:'确定'
							})
						}
					})
					}
				})
			}
		}
	}
</script>
<style>
	.content {
		padding-top: 20px;
	}

	.upload {
		width: 30%;
		height: 110px;
		display: block;
		margin: auto;
	}
</style>
